package com.demo.java.runa;

import cn.hutool.log.StaticLog;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class StatePrinter implements Runnable {

    Map<String,Thread> threadMap;
    public StatePrinter(Map<String,Thread> threadMap){
        this.threadMap = threadMap;
    }

    @Override
    public void run() {
        for(int i=0;i<30;i++){
            try {
                print(threadMap);
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static void print(Map<String,Thread> threadMap){
        List<String> message = new ArrayList<>();
        for(Map.Entry<String,Thread> entry:threadMap.entrySet()){
            message.add(entry.getKey()+"["+entry.getValue().getId()+"]:"+String.format("%13s",entry.getValue().getState().name()));
        }
        StaticLog.info(String.join("   ",message));
    }
}
